import {dclist} from './dc.js';
import sqlite3 from 'sqlite3';

const db =new sqlite3.Database('d:/yu/projs/bcz/vocab-server-nest/lookup.db');

const getWordFromTable = async (word) => {
    return new Promise((resolve,reject)=>{
        const result = db.get(`SELECT * FROM dict_bcz WHERE word = ?`, [word],(err,rows)=>{
            resolve(rows);
        });
    });
};

    const stringArrayToObject = async (array) => {
        let obj={};
        for(let item of array){
            obj[item] = await getWordFromTable(item);
        }
        return obj;

        // return array.reduce((obj, item) => {
        // return array.reduce((obj, item, index) => {
        //     obj[item] = getWordFromTable(item);
        //     return obj;
        // }, {});
    };


    const dcobj={};
    for(let item in dclist){
        dcobj[item]=await stringArrayToObject(dclist[item]);
    }
    //Object.entries(dclist).map(async ([key, value]) => [key,await stringArrayToObject(value)])
    

    //const dcobj = await getWordFromTable("hello");
    console.log(dcobj);
